//package run.siyuan.rabbitmq.delay.message.config;
//
//import org.springframework.amqp.core.Binding;
//import org.springframework.amqp.core.BindingBuilder;
//import org.springframework.amqp.core.FanoutExchange;
//import org.springframework.amqp.core.Queue;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@Configuration
//public class TtlDelayRabbitConfig {
//
//    //路由ttl消息交换机
//    @Bean("ttlDelayFanoutExchange")
//    public FanoutExchange fanoutExchange(){
//        return new FanoutExchange("TTL_DELAY_FANOUT_EXCHANGE");
//    }
//
//    //ttl消息队列
//    @Bean("ttlDelayQueue")
//    public Queue ttlQueue(){
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("x-message-ttl", 5000);//队列中所有消息5秒后过期
//        map.put("x-dead-letter-exchange", "TTL_DELAY_DEAD_LETTER_FANOUT_EXCHANGE");//过期后进入死信队列
//        return new Queue("TTL_QUEUE",false,false,false,map);
//    }
//
//    //Fanout交换机和productQueue绑定
//    @Bean
//    public Binding bindTtlFanoutExchange(@Qualifier("ttlDelayQueue") Queue queue, @Qualifier("ttlDelayFanoutExchange") FanoutExchange fanoutExchange){
//        return BindingBuilder.bind(queue).to(fanoutExchange);
//    }
//
//    //fanout死信交换机
//    @Bean("ttlDelayDeadLetterExchange")
//    public FanoutExchange deadLetterExchange(){
//        return new FanoutExchange("TTL_DELAY_DEAD_LETTER_FANOUT_EXCHANGE");
//    }
//
//    //死信队列
//    @Bean("ttlDelayDeadLetterQueue")
//    public Queue ttlDelayDeadLetterQueue(){
//        return new Queue("TTL_DELAY_DEAD_LETTER_FANOUT_QUEUE");
//    }
//
//    //死信队列和死信交换机绑定
//    @Bean
//    public Binding deadLetterQueueBindExchange(@Qualifier("ttlDelayDeadLetterQueue") Queue queue, @Qualifier("ttlDelayDeadLetterExchange") FanoutExchange fanoutExchange){
//        return BindingBuilder.bind(queue).to(fanoutExchange);
//    }
//}